#include <scdl/parser/Symbol.hpp>
#include <scdl/parser/internal.hpp>

#include <cstdlib>
#include <cstring>
#include <iostream>

using std::cout;
using namespace scdl;

List::List()
{
}

List::~List()
{
}

SymbolCategory List::getCategory()
{
        return CATEGORY_LIST;
}

void List::prettyPrint(bool verbose)
{
        cout << "[ ";
        for (int i = 0; i < size; i++) {
                elements[i]->prettyPrint();
                cout << " ";
        }
        cout << "]";
}

void List::determineType(Symbol *expected)
{
        typed = true;

        Symbol *type = 0;
        int num = getNrElements();
        for (int i = 1; i < num; i++) {
                Symbol *etype = getElement(i)->getType(expected);
                if (type == 0)
                        type = etype;
                else if (!checkType(etype, type, true))
                        return;
        }

        setType(type);
}

Symbol *List::getSort()
{
        if (size)
                return getElement(0);
        return 0;
}

int List::getNrArguments()
{
        return (getNrElements() - 1);
}

Symbol *List::getArgument(int idx)
{
        return getElement(idx + 1);
}
